const db = require('./db')

// db.col('fruits') // 拿不到数据库连接实例

db.once('connect', async () => {
    let col = db.col('fruits')

    try {
        await col.deleteMany()
        // 
        await col.insertMany([
            { name: '苹果', price: 18.9, category: '水果' },
            { name: '芒果', price: 18.9, category: '水果' },
            { name: '车厘子', price: 18.9, category: '水果' },
            { name: '提子', price: 18.9, category: '水果' },

            { name: '白菜', price: 18.9, category: '蔬菜' },
            { name: '土豆', price: 18.9, category: '蔬菜', stack: 100 },
            { name: '韭菜', price: 18.9, category: '蔬菜', stack: 100 },
            { name: '芹菜', price: 18.9, category: '蔬菜' },
        ])
        console.log('插入成功')
    } catch (error) {
        console.error(error)
    }

})
